{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h1 align=\"center\"> Python Basics</h1>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Table of Contents\n",
    "\n",
    "<ul>\n",
    "  <li>[Installing Python (Anaconda)](#Install-Anaconda)</li>\n",
    "  <li>[Hello World!](#Hello-World!)</li>\n",
    "  <li>[String Manipulation](#String-Manipulations)\n",
    "  </li>\n",
    "  <li>[Simple Math](#Simple-Math)</li>\n",
    "  <li>[if elif else](#if-elif-else)</li>\n",
    "  <li>[for loops](#For-Loops)</li>\n",
    "  <li>[Testing your Knowledge (Fizz Buzz)](#Fizz-Buzz)</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Why Python\n",
    "\n",
    "Python is Open Source (Free). Lots of people from around the world are continually improving python. Used worldwide at top tier companies (youtube, google, yelp, etc) <br>\n",
    "\n",
    "Also Nature recommends it [(link)](http://www.nature.com/news/programming-pick-up-python-1.16833)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Why IPython/Jupyter\n",
    "\n",
    "The IPython Notebook is another popular package — “a coder's lab notebook” — that allows users to interleave data, code and explanatory text in a single browser-based page, rather than in separate files"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Install Anaconda\n",
    "If you don't have python installed, please see the blog post or youtube video for your operating system (Mac, Windows Ubuntu)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Operating System | Blog Post | Youtube Video\n",
    "--- | --- | ---\n",
    "Mac | [Install Anaconda on Mac](https://medium.com/@GalarnykMichael/install-python-on-mac-anaconda-ccd9f2014072#.lvhw2gt3k \"Install Anaconda on Mac\") | [Youtube Video](https://www.youtube.com/watch?v=B6d5LrA8bNE \"Youtube Video\")\n",
    "Ubuntu | [Install Anaconda on Ubuntu](https://medium.com/@GalarnykMichael/install-python-on-ubuntu-anaconda-65623042cb5a#.4kwsp0wjl \"Install Anaconda on Ubuntu\") | [Youtube Video](https://www.youtube.com/watch?v=jo4RMiM-ihs \"Youtube Video\")\n",
    "Windows | [Install Anaconda on Windows](https://medium.com/@GalarnykMichael/install-python-on-windows-anaconda-c63c7c3d1444#.66f7y3whf \"Install Anaconda on Windows\") | [Youtube Video](https://www.youtube.com/watch?v=dgjEUcccRwM \"Youtube Video\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Basic Types\n",
    "\n",
    "The main basic data types in python are numbers (ints and floats), booleans and strings."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Hello World!\n",
    "alphanumeric characters in quotations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World!\n"
     ]
    }
   ],
   "source": [
    "# This is a one line comment\n",
    "print('Hello World!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World!\n"
     ]
    }
   ],
   "source": [
    "# Strings can be enclosed by ',\", or \"\"\"\n",
    "print(\"Hello World!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# \\ is used as a escape character. \n",
    "# There are many special escape sequences\n",
    "# Notable are: \\t (tab)\n",
    "#             \\n (new line)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The \n",
      " makes a new line\n"
     ]
    }
   ],
   "source": [
    "print(\"The \\n makes a new line\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The \t is a tab\n"
     ]
    }
   ],
   "source": [
    "print(\"The \\t is a tab\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I'm going to the movies\n"
     ]
    }
   ],
   "source": [
    "print('I\\'m going to the movies')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This is a string enclosed by \"\" not '' \n"
     ]
    }
   ],
   "source": [
    "# Using \\ to not accidently close the string by having a closing \"\n",
    "print(\"This is a string enclosed by \\\"\\\" not '' \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World\n"
     ]
    }
   ],
   "source": [
    "# Creating a variable\n",
    "# Variables are used to store information to be referenced \n",
    "# and manipulated in a computer program.\n",
    "\n",
    "firstVariable = 'Hello World'\n",
    "print(firstVariable)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### String Manipulations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Strings are a special type of a python class. As objects, in a class, you can call methods on string objects using the .methodName() notation. The string class is available by default in python, so you do not need an import statement to use the object interface to strings."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n",
      "HELLO WORLD\n",
      "Hello World\n"
     ]
    }
   ],
   "source": [
    "# go over ? mark after if you are not sure what method does. \n",
    "print(firstVariable.lower())\n",
    "print(firstVariable.upper())\n",
    "print(firstVariable.title())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# To look up what each method does\n",
    "firstVariable.lower?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function lower:\n",
      "\n",
      "lower(...)\n",
      "    S.lower() -> string\n",
      "    \n",
      "    Return a copy of the string S converted to lowercase.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Can also use help\n",
    "help(firstVariable.lower)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "help"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Hello', 'World']"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "firstVariable.split(' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Hello', 'World']"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a=firstVariable.split(' ')\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Hello World'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "' '.join(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "01\n"
     ]
    }
   ],
   "source": [
    "print(\"0\" + \"1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'000'"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"0\" * 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'FizzBuzz'"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# You can add strings together. \n",
    "\"Fizz\" + \"Buzz\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Simple Math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are four distinct numeric types: plain integers, long integers, floating point numbers, and complex numbers. In addition, Booleans are a subtype of plain integers."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 138,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Addition, add two int together\n",
    "1+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "128.0"
      ]
     },
     "execution_count": 139,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# if one of the operands is a float, the result is a float.\n",
    "130-2.0  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "128"
      ]
     },
     "execution_count": 140,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "130-2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "65.0"
      ]
     },
     "execution_count": 141,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# integer division\n",
    "130/2    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "65.0"
      ]
     },
     "execution_count": 142,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "130.0/2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Multiplication\n",
    "2*3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 144,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Exponentiation ** \n",
    "# This operator raises the number to its left to the power of the number to its right \n",
    "2**3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 145,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Modulo\n",
    "# Returns the remainder of the division of the number to the left by the \n",
    "# number on its right. \n",
    "9%3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## if statement"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Comparison Operator | Function\n",
    "--- | --- \n",
    "< | less than\n",
    "<= | less than or equal to\n",
    "> | greater than\n",
    ">= | greater than or equal to\n",
    "== | equal\n",
    "!= | not equal"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "check if something is True, if it is, do it. If it is not True (False), don't do it<br>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "# Notice you have to indent after you start a if statement. \n",
    "num = 3\n",
    "if num == 3: \n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Nothing is outputted because num > 10 is FALSE\n",
    "num = 3\n",
    "if num > 10:\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fizz\n"
     ]
    }
   ],
   "source": [
    "num = 3\n",
    "if num % 3 == 0:\n",
    "    print(\"Fizz\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Buzz\n"
     ]
    }
   ],
   "source": [
    "num = 10\n",
    "if num % 5 == 0:\n",
    "    print(\"Buzz\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This was True\n"
     ]
    }
   ],
   "source": [
    "if True:\n",
    "    print(\"This was True\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "if False: \n",
    "    print(\"Nothing printed\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Logical Operator | Description\n",
    "--- | ---\n",
    "and | If both the operands are True then condition becomes True.\n",
    "or | If any of the two operands are True then condition becomes True. \n",
    "not | Used to reverse the logical (not False becomes True, not True becomes False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 152,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "num = 4\n",
    "num > 0 and num  < 15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n"
     ]
    }
   ],
   "source": [
    "# both the conditions are true, so the num will be printed out\n",
    "if num > 0 and num  < 15:\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 154,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# num > 0 is True, num > 15 is False\n",
    "# Since the first condition is True, it is True\n",
    "num = 4\n",
    "num > 0 or num  > 15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n"
     ]
    }
   ],
   "source": [
    "if num > 0 or num  > 15:\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# or will only evaluate to False if both are False\n",
    "if False or False:\n",
    "    print('Nothing will print out')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 157,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "num = 10\n",
    "not num < 20 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## else statement"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Must be after an if or elif statement. There can be at most one else statement. Will only be executed if all the \"if\" and \"elif\" statements above it are False. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "num = 1\n",
    "if num > 3 :\n",
    "    print(\"Hi\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number is not greater than 3\n"
     ]
    }
   ],
   "source": [
    "\"\"\"We will execute what is inside the else statement\n",
    "because num is not greater than 3\n",
    "\"\"\"\n",
    "num = 1\n",
    "if num > 3 :\n",
    "    print(\"Hi\")\n",
    "else: \n",
    "    print(\"number is not greater than 3\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hi\n"
     ]
    }
   ],
   "source": [
    "\"\"\"We will execute what is inside the if statement because num > 4\"\"\"\n",
    "num = 4\n",
    "if num > 3 :\n",
    "    print(\"Hi\")\n",
    "else: \n",
    "    print(\"number is not greater than 3\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<b>Task</b>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Assign num to an integer value. \n",
    "2. Write an if else combination that will print \"Your integer is even\" if the integer is even. Otherwise, print \"Your integer is odd\". "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Hint: Any integer that can be divided exactly by 2 is an even number (examples: 2, 4, 6). Any integer that cannot be divided exactly by 2 is an odd number (examples: 1, 3, 5). Use the modulo operator (%) which returns the remainder of the division of the number to the left by the number on its right. \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Your integer is odd\n"
     ]
    }
   ],
   "source": [
    "num = 3\n",
    "if num % 2 == 0:\n",
    "    print(\"Your integer is even\")\n",
    "else: \n",
    "    print(\"Your integer is odd\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## elif statement"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Must be after an if statement. elif statement statement allows you to check multiple expressions for True and execute a block of code as soon as one of the conditions evaluates to True.\n",
    "\n",
    "Similar to the else, the elif statement is optional. However, unlike else, for which there can be at most one statement, there can be an arbitrary number of elif statements following an if."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "num = 21\n"
     ]
    }
   ],
   "source": [
    "num = 21\n",
    "if num > 50:\n",
    "    print('num is larger than 50')\n",
    "elif num == 21:\n",
    "    print('num = 21')\n",
    "else:\n",
    "    print('Catchall condition')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Your number is odd\n"
     ]
    }
   ],
   "source": [
    "my_num = 5\n",
    "if my_num % 2 == 0:\n",
    "    print(\"Your number is even\")\n",
    "elif my_num % 2 != 0:\n",
    "    print(\"Your number is odd\")\n",
    "else: \n",
    "    print(\"Are you sure your number is an integer?\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Later on in the tutorial series, we will go over simulating dice rolls and talking about the distribution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "You rolled a 1. Great job!\n"
     ]
    }
   ],
   "source": [
    "# You can have mulitple elif statements. \n",
    "# Remember only the first True statement has its block of code executed. \n",
    "\n",
    "dice_value = 1\n",
    "if dice_value == 1:\n",
    "    print('You rolled a {}. Great job!'.format(dice_value))\n",
    "elif dice_value == 2:\n",
    "    print('You rolled a {}. Great job!'.format(dice_value))\n",
    "elif dice_value == 3:\n",
    "    print('You rolled a {}. Great job!'.format(dice_value))\n",
    "elif dice_value == 4:\n",
    "    print('You rolled a {}. Great job!'.format(dice_value))\n",
    "elif dice_value == 5:\n",
    "    print('You rolled a {}. Great job!'.format(dice_value))\n",
    "elif dice_value == 6:\n",
    "    print('You rolled a {}. Great job!'.format(dice_value))\n",
    "else:\n",
    "    print('None of the conditions above (if elif) were evaluated as True')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<b>Task</b>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Assign num to an integer value. \n",
    "2. Write a series of if, elif, else statements that will print the num you assigned. But for multiples of three print \"Fizz\" instead of the number and for the multiples of five print \"Buzz\". For numbers which are multiples of both three and five print \"FizzBuzz\"."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Solution 1\n",
    "num = 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Buzz\n"
     ]
    }
   ],
   "source": [
    "if num % 3 == 0 and num % 5 == 0:\n",
    "    print('FizzBuzz')\n",
    "elif num % 3 == 0:\n",
    "    print('Fizz')\n",
    "elif num % 5 == 0:\n",
    "    print('Buzz')\n",
    "else:\n",
    "    print(str(num))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Solution 2\n",
    "num = 15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "FizzBuzz\n"
     ]
    }
   ],
   "source": [
    "\"\"\"Notice how difficult this solution is relative to Solution 1\"\"\"\n",
    "\n",
    "string = \"\"\n",
    "if num % 3 == 0:\n",
    "    string = string + \"Fizz\"\n",
    "if num % 5 == 0:\n",
    "    string = string + \"Buzz\"\n",
    "if num % 5 != 0 and num % 3 != 0:\n",
    "    string = string + str(num)\n",
    "print(string)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Lists"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Lists are written within square brackets [ ]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " |  |  |  |\n",
    "--- | --- | --- | --- | ---\n",
    "z =| [3, | 7, | 4, | 2]\n",
    "index | 0 | 1 | 2 | 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Defining a list\n",
    "z = [3, 7, 4, 2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Accessing Values in List"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The first element of a list is at index 0\n",
    "z[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "z[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Access Last Element of List \n",
    "z[-2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "### Slicing Lists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[3, 7]"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# first index is inclusive (before the :) and last (after the :) is not. \n",
    "# not including index 2\n",
    "z[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[3, 7, 4]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# everything up to index 3\n",
    "z[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[7, 4, 2]"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# index 1 to end of list\n",
    "z[1:]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Minimum, Maximum, Length, and Sum of a list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2 7 4 16\n"
     ]
    }
   ],
   "source": [
    "print(min(z), max(z), len(z), sum(z))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Count Number of Times Value is in List"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random_list = [4, 1, 5, 4, 10, 4]\n",
    "random_list.count(4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Return First Index of Value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " |  |  |  |  |  |\n",
    "--- | --- | --- | --- | --- | --- | ---\n",
    "random_list =| [4, | 1, | 5, | 4, | 10, | 4]\n",
    "index=| 0 | 1 | 2 | 3 | 4 | 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random_list.index(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# you can specify where you start your search\n",
    "random_list.index(4, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 180,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# random_list.index(value, [start, stop])\n",
    "random_list.index(4, 5, 6)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Sorting a list "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "x = [3, 7, 2, 11, 8, 10, 4]\n",
    "y = ['Steve', 'Rachel', 'Michael', 'Adam', 'Monica', 'Jessica', 'Lester']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 3, 4, 7, 8, 10, 11]\n"
     ]
    }
   ],
   "source": [
    "# Sorting and Altering original list\n",
    "# low to high\n",
    "x.sort()\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[11, 10, 8, 7, 4, 3, 2]\n"
     ]
    }
   ],
   "source": [
    "# Sorting and Altering original list\n",
    "# high to low\n",
    "x.sort(reverse = True)\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Adam', 'Jessica', 'Lester', 'Michael', 'Monica', 'Rachel', 'Steve']\n"
     ]
    }
   ],
   "source": [
    "# Sorting and Altering original list\n",
    "# A-Z\n",
    "y.sort()\n",
    "print(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Steve', 'Rachel', 'Monica', 'Michael', 'Lester', 'Jessica', 'Adam']\n"
     ]
    }
   ],
   "source": [
    "# Sorting and Altering original list\n",
    "# Z-A\n",
    "y.sort(reverse = True)\n",
    "print(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Adam', 'Jessica', 'Lester', 'Michael', 'Monica', 'Rachel', 'Steve']"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# sorting list WITHOUT altering original list \n",
    "new_list = sorted(y)\n",
    "new_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Steve', 'Rachel', 'Monica', 'Michael', 'Lester', 'Jessica', 'Adam']"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# notice y is unchanged\n",
    "y"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Add to the End of List"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[11, 10, 8, 7, 4, 3, 2]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[11, 10, 8, 7, 4, 3, 2, 3]\n"
     ]
    }
   ],
   "source": [
    "x.append(3)\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Remove First Occurence of Value in List"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[11, 8, 7, 4, 3, 2, 3]\n"
     ]
    }
   ],
   "source": [
    "x.remove(10)\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Remove Item at the Index you Provide"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[11, 8, 7, 4, 3, 2, 3]\n"
     ]
    }
   ],
   "source": [
    "# List before you remove an item\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Remove item at the index\n",
    "# this function will also return the item you removed from the list\n",
    "# Default is the last index\n",
    "x.pop(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[11, 8, 7, 3, 2, 3]\n"
     ]
    }
   ],
   "source": [
    "print(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Extend (Useful for Concatenating Lists)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Extend list by appending elements (iterable)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "x.extend([4, 5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[11, 8, 7, 3, 2, 3, 4, 5]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can also use + for concatenating lists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x+y= [11, 8, 7, 3, 2, 3, 4, 5, 'Steve', 'Rachel', 'Monica', 'Michael', 'Lester', 'Jessica', 'Adam']\n"
     ]
    }
   ],
   "source": [
    "# lists can be diverse, each element in the list can be of a different type.\n",
    "# lists are really list of pointers, and these pointers can \n",
    "# point to anything.\n",
    "\n",
    "# Concatenating Lists\n",
    "print('x+y=',x+y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Insert Item before the Index you Provide"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[11, 8, 7, 3, 2, 3, 4, 5]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 197,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "x.insert(4, [4, 5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 198,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[11, 8, 7, 3, [4, 5], 2, 3, 4, 5]"
      ]
     },
     "execution_count": 198,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
